﻿
using Chain.BLL;
//    using ChainStock.Controls;
using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class RptMoneyExchange : PageBase
{


    private void BindMoneyChange()
    {
    }

    private void BindMoneyChangeType(HtmlSelect select, bool bolAddEmpty)
    {
        select.Items.Clear();
        if (bolAddEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        select.Items.Add(new ListItem("分享得红包", "1"));
        select.Items.Add(new ListItem("后台零钱提现到红包", "2"));
        select.Items.Add(new ListItem("前台零钱提现到红包", "3"));

    }
    protected void btnMoneyExchangeExcel_Click(object sender, EventArgs e)
    {
        string strSql = this.QueryCondition();
        int Counts = this.NetPagerParameter.RecordCount;
        strSql = PubFunction.GetShopAuthority(base._UserShopID, "UserShopID", strSql);
        WxRedPacketsList redpocketLogBll = new WxRedPacketsList();
        DataTable db = redpocketLogBll.GetWxRedPocketLog(0x186a0, 1, out Counts, new string[] { strSql }).Tables[0];
        DataExcelInfo.WxPocketLogReportExcel(db, base._UserName);
    }

    protected void btnMoneyExchangeSearch_Click(object sender, EventArgs e)
    {
        this.BindMoneyChange();
        this.Get_ParameterList(this.QueryCondition());
    }

    protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.NetPagerParameter.CurrentPageIndex = 1;
        this.NetPagerParameter.PageSize = int.Parse(this.drpPageSize.SelectedValue);
        this.BindMoneyChange();
        this.Get_ParameterList(this.QueryCondition());
    }

    private void Get_ParameterList(string strSql)
    {
        int Counts = this.NetPagerParameter.RecordCount;
        strSql = PubFunction.GetShopAuthority(base._UserShopID, "UserShopID", strSql);
        WxRedPacketsList RedPocketLogBll = new WxRedPacketsList();
        DataTable db = RedPocketLogBll.GetWxRedPocketLog(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts, new string[] { strSql }).Tables[0];
        this.NetPagerParameter.RecordCount = Counts;
        this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[] { this.NetPagerParameter.CurrentPageIndex, this.NetPagerParameter.PageCount, this.NetPagerParameter.RecordCount, this.NetPagerParameter.PageSize });
        this.gvMoneyExchange.DataSource = db;
        this.gvMoneyExchange.DataBind();
        PageBase.BindSerialRepeater(this.gvMoneyExchange, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
    }

    protected string GetExchangeType(object obj)
    {
        switch (Convert.ToInt32(obj))
        {
            case 1:
                return "分享得红包";
            case 2:
                return "后台零钱提现到红包";
            case 3:
                return "前台零钱提现到红包";
        }
        return "未知类型";
    }


    protected string GetExchangeState(object obj)
    {
        switch (Convert.ToInt32(obj))
        {
            case 1:
                return "成功";

            case 0:
                return "失败";
        }
        return "未知类型";
    }



    protected void NetPagerParameter_PageChanging(object src, PageChangingEventArgs e)
    {
        this.NetPagerParameter.CurrentPageIndex = e.NewPageIndex;
        this.BindMoneyChange();
        this.Get_ParameterList(this.QueryCondition());
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            PubFunction.BindShopSelect(base._UserShopID, this.sltShop, true);
            this.BindMoneyChangeType(this.sltdMoneyChangeType, true);
            this.BindMoneyChange();
            this.Get_ParameterList(this.QueryCondition());
        }
    }

    private string QueryCondition()
    {
        string strQueryMem = this.txtQueryMem.Value.Trim();
        string shopID = this.sltShop.Value;
        string startTime = this.txtStartTime.Value;
        string endTime = PubFunction.TimeEndDay(this.txtEndTime.Value);
        string changeType = this.sltdMoneyChangeType.Value;
        StringBuilder strSql = new StringBuilder();
        strSql.Append("1=1 ");
        if (!string.IsNullOrEmpty(strQueryMem))
        {
            strSql.AppendFormat("and (MemCard ='{0}' or MemName like '%{0}%' or MemMobile='{0}' or MemCardNumber = '{0}' ) ", strQueryMem);
        }
        if (!string.IsNullOrEmpty(shopID))
        {
            strSql.AppendFormat("and ShopID={0} ", shopID);
        }
        if (!string.IsNullOrEmpty(startTime))
        {
            strSql.AppendFormat("and datetime>='{0}' ", startTime);
        }
        if (!string.IsNullOrEmpty(endTime))
        {
            strSql.AppendFormat("and datetime<='{0}' ", endTime);
        }
        if (!string.IsNullOrEmpty(changeType))
        {
            strSql.AppendFormat("and type={0} ", changeType);
        }
        strSql.Append("and WxRedPacketsList.memid=Mem.MemID and SysUser.UserShopID=SysShop.ShopID and SysUser.UserID="+base._UserID);
       

        return strSql.ToString();
    }
}


